package cn.jhc.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.jhc.dao.DaoType;
import cn.jhc.dao.PublisherDAO;
import cn.jhc.factory.DAOFactory;

/**
 * Servlet implementation class DelPublisherServlet
 */
@WebServlet("/delpublisher.htm")
public class DelPublisherServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DelPublisherServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String par = request.getParameter("oneid");
		if(par == null){
			String[] str = request.getParameterValues("publisherid");
			for(String s : str){
				int id = Integer.parseInt(s);
				PublisherDAO pdao = (PublisherDAO)DAOFactory.getDao(DaoType.PUBLISHER);
				pdao.deletePublisher(id);
			}
		}
		else{
			int id = Integer.parseInt(par);
			PublisherDAO pdao = (PublisherDAO)DAOFactory.getDao(DaoType.PUBLISHER);
			pdao.deletePublisher(id);
		}
		
		request.getRequestDispatcher("/admin/admin.jsp?body=/showpublisher.htm").forward(request, response);
	}


	
}